package com.fz.song.interceptor;


import com.fz.song.config.BlogConfig;
import com.fz.song.pojo.BlogAdmin;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class PrintHTTPInterceptor implements HandlerInterceptor {

    private static Log logger = LogFactory.getLog(PrintHTTPInterceptor.class);


    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        if (handler instanceof HandlerMethod) {
            HandlerMethod authhandler = (HandlerMethod) handler;
            printHTTP(request, authhandler);
        }
        return true;
    }

    private void printHTTP(HttpServletRequest request, HandlerMethod handler) {
        logger.info("--------------------- Request Start ------------------------");
        logger.info("请求 URL：" + request.getRequestURI());
        logger.info("控制器类：" + handler.getBeanType().getName());
        logger.info("页面URL类方法名：" + handler.getMethod().getName());
        logger.info("--------------------- Request End --------------------------");
    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object o, ModelAndView modelAndView) throws Exception {

    }

    @Override
    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object o, Exception e) throws Exception {

    }
}
